<template>
	<view class="content">
		<!-- #ifdef H5 || APP-PLUS -->
		<view class="message-title">
			<commonTitle title="签到中心"></commonTitle>
		</view>
		<!-- #endif -->
		
		<view class="list-scroll-content nopadding">
			<!-- 每日签到 -->
			<view class="sign-day">
				<view class="sign-baseInfo">	
					<view class="sign-baseInfo-totalcoin paddingLeft">
						<image src="../../static/common/baseinfo-user.png" class="baseinfo-user-icon"></image>
						<view class="user-conin-title">我的鼓励金</view>
						<view class="user-conin-num">
							<view class="coin-number">{{gulijin}}</view>
							<view class="money-tag">元</view>
						</view>
					</view>
					
					<view class="sign-baseInfo-totalcoin signborder">
						<image src="../../static/common/baseinfo-sign.png" class="baseinfo-user-icon"></image>
						<view class="user-conin-title">已连续签到</view>
						<view class="user-conin-num">
							<view class="coin-number">{{data.sign_count?data.sign_count:0}}</view>
							<view class="money-tag">天</view>
						</view>
					</view>
				</view>
				<view class="sign-btn" @tap="doSign">
					{{data.today_sign==1?"已签到":"签到领鼓励金"}}
				</view>
			</view>
			<!-- 签到地图 -->
			<model-calendar
			:sendYear="toYear" :sendMonth="toMonth"
			:dataSource="signData" :totalNum="sumCount"
			 @dateChange="getData" @clickChange="clickRegister"	 >
			 </model-calendar>
			<!-- 签到奖励金 -->
			<view class="sign-bonus">
				<view class="sign-bonus-title">你已连续签到<text class="special-color">{{data.sign_count?data.sign_count:0}}</text>天,再签到<text class="special-color">{{data.sign_count?getDays(data.sign_count):7}}</text>天可领取鼓励金奖励</view>
				<view class="bouns-type">
					<view class="bouns-type-item">
						<image src="../../static/common/7days-bouns-y.png" class="days7-bouns"></image>
						<view class="days">7天</view>
						<view class="bouns-btn">奖励金+0.2</view>
					</view>
					<view class="bouns-type-item days15">
						<image src="../../static/common/15days-bouns-y.png" class="days15-bouns"></image>
						<view class="days">15天</view>
						<view class="bouns-btn">奖励金+0.5</view>
					</view>
					<view class="bouns-type-item">
						<image src="../../static/common/30days-bouns-y.png" class="days30-bouns"></image>
						<view class="days">30天</view>
						<view class="bouns-btn">奖励金+1</view>
					</view>
				</view>
			</view>
			<!-- 签到成功 -->
			<!-- <view class="sign-success" v-if="signSuccess">
				<image src="../../static/common/sign-success.png" class="sign-success-img"></image>
				<image src="../../static/common/sign-close.png" class="sign-close"></image>
			</view> -->
		</view>
		<uni-popup ref="showshare" :type="type">
			<view class="uni-share">
				<image src="../../static/common/sign-success.png" class="sign-success-img"></image>
				<image src="../../static/common/sign-close.png" class="sign-close" @tap="closeShare"></image>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import commonTitle from'../../components/titile/title.vue'
	import modelCalendar from'../../components/calendar/calendar.vue'
	import uniPopup  from'../../components/uni-popup/uni-popup.vue'
	export default{
		name:"signIn",
		data(){
			return{
				toYear: parseInt(new Date().getFullYear()), //本日
				toMonth: parseInt(new Date().getMonth() + 1), //本月
				sumCount: 3,
				signData: [],
				signSuccess:false,
				apptoken:"",
				signList:"",
				gulijin:"",
				signDays:0,
				type: 'center',
				data:""
			}
		},
		components:{
			commonTitle,
			modelCalendar,
			uniPopup
		},
		onLoad() {
			this.apptoken = uni.getStorageSync("apptoken");
			//加载我的鼓励金
			this.getGulijin();
			//加载我的签到记录
			this.getSignList();
		},
		methods:{
			getDays(sign_count){
				if(sign_count<7){
					return (7 - sign_count)
				}else if(7<sign_count<15){
					return (15 - sign_count)
				}else if(15<sign_count<30){
					return (30 - sign_count)
				}
			},
			openOrder(){
				 this.$refs.showshare.open();
			},
			closeShare(){
				 this.$refs.showshare.close();
				 //加载我的鼓励金
				 this.getGulijin();
				 //加载我的签到记录
				 this.getSignList();
			},
			doSign(){
				const _this = this;
				if(this.data.today_sign != 1){
					uni.request({
						url:this.$API.URL + this.$API.userSign,
						data:{apptoken:this.apptoken},
						success(res) {
							console.log(res)
							if(res.data.success){
								_this.openOrder();
								//_this.signSuccess = !_this.signSuccess;
								_this.data.today_sign = 0;
								res.data.data.sign_array.forEach(item=>{
									_this.signData.push(item)
								})
								
							}else{
								_this.$CommonJS.showToast(res.data.msg);
							}
						}
					})
				}else{
					this.$CommonJS.showToast("今日已签到,无需重复签到")
				}
				
			},
			getGulijin(){
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.userView,
					data:{
						apptoken:this.apptoken
					},
					success(res) {
							console.log(res)
							if(res.data.success){
								_this.gulijin = res.data.data.gulijin;
								uni.setStorage({
									key:"gulijin",
									data:res.data.data.gulijin
								})
							}
					}
				})
			},
			getSignList(){
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.userSignRecord,
					data:{apptoken:this.apptoken},
					success(res) {
						console.log(res)
						if(res.data.success){
							res.data.data.sign_array.forEach(item=>{
								_this.signData.push(item);
								_this.data = res.data.data;
							})
						}
					}
				})
			},
			getData(){
				
			},
			clickRegister(){
				
			}
		}
	}
</script>

<style>
	@import url("signin.css");
	.uni-share{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>
